<?php
include "../include/global.php";
include "../include/admin_check.php";
$xtpl = new XTemplate ("travelstyle.htm");
include "setting.php";
//
include "../include/function.php";
$xtpl->assign("left_panel", left_panel());
$xtpl->assign("header_panel", header_panel());
$xtpl->assign("footer_panel", footer_panel());

// ++ lang
if($lang=='v'){
	$xtpl->assign('type_vietnamese', 'onkeyup="initTyper(this)"');
}
$xtpl->assign("title", TravelStyle);
$xtpl->assign("lbl_search", Search);
$xtpl->assign("lbl_no", No);
$xtpl->assign("lbl_name", Name);
$xtpl->assign("lbl_position", Position);
$xtpl->assign("lbl_active", Active);
$xtpl->assign("lbl_update", Update);
$xtpl->assign("lbl_edit", Edit);
$xtpl->assign("lbl_delete", Delete);
$xtpl->assign("lbl_addnew", Addnew);
$xtpl->assign("lbl_total", Total);
$xtpl->assign("lbl_row", Row);
// -- lang
//
$hiddenID=$_POST['hiddenID'];
$chkIsActive=$_POST['chkIsActive'];
$textbox1=$_POST['textbox1'];

if($_POST['ac']=="update"){
     //////
   for ($i=0;$i<count($hiddenID);$i++) {
		 $sql = "UPDATE ".pre_table."travelstyle SET travelstyle_isactive=0 WHERE travelstyle_id = '$hiddenID[$i]'";
		 $rs = execSQL($sql);				
   }  
   //////
   for ($i=0;$i<count($chkIsActive);$i++) {
		$ActiveList.=$chkIsActive[$i].",";
   }
   if($ActiveList) {
		$ActiveList = substr($ActiveList,0,strlen($ActiveList)-1);
		$ActiveSplit=split(",",$ActiveList);
		for($i=0;$i<count($ActiveSplit);$i++){
		   $ActiveRow=split("~",$ActiveSplit[$i]);
		   $sql = "UPDATE ".pre_table."travelstyle SET travelstyle_isactive=1 WHERE travelstyle_id=$ActiveRow[0]";
		   execSQL($sql);  				   
		}
	}
   for ($i=0;$i<count($textbox1);$i++) {
         $sql = "UPDATE ".pre_table."travelstyle SET travelstyle_position='$textbox1[$i]' WHERE travelstyle_id = '$hiddenID[$i]'";
	     $rs = execSQL($sql);				
   }  
}
if($_POST['ac']=="delete"){
	  $check_delete =  $_POST["checked_delete"];      
	  for ($i=0;$i<count($check_delete);$i++) {
			$delete_list .= $check_delete[$i].",";
	  }
	  if($delete_list){
			$delete_list = substr($delete_list,0,strlen($delete_list)-1);
			$delete_split=split(",",$delete_list); 
			for($i=0;$i<count($delete_split);$i++){
				$sql = "DELETE FROM ".pre_table."travelstyle WHERE travelstyle_id = '$delete_split[$i]'";
				execSQL($sql);
			}
	  }
}

$page=intval($_GET['page']);
$limit=30;$pagegroup_size=10;
if (!$page||$page==0){$page=1;}
$offset=($page-1)*$limit;
$xtpl->assign("page",$page);

$condition="";
$condition.=" AND lang='".$lang."'";

$key=$_POST['key'];
if($key){
   $condition.=" and (c.travelstyle_name like '%$key%')";
}
$xtpl->assign("key",$key);

$stsql = "SELECT c.* FROM ".pre_table."travelstyle c WHERE 1=1".$condition;
$rssql = execSQL($stsql);
$numrec=mysql_num_rows($rssql);
$OrderNo=1+$numrec-($page-1)*$limit;
$sql="SELECT c.* FROM ".pre_table."travelstyle c WHERE 1=1".$condition." order by travelstyle_position asc limit $offset, $limit";
$rs = execSQL($sql);
while($row = mysql_fetch_array($rs)){
    
	$OrderNo=--$OrderNo;
	$row[OrderNo] = $OrderNo;

	$row[ActiveSite] = $row[travelstyle_isactive];
	$row[travelstyle_isactive] = ($row[travelstyle_isactive]==0?"":"checked");

    $xtpl->insert_loop("MAIN.list",array("list"=>$row));	
}

$pages=pagenavigator($page,$numrec,$limit,$pagegroup_size,"m","travelstyle.php?key=$key");
$xtpl->assign("pages",$pages);
$xtpl->assign("numrec",$numrec);

//
$xtpl->parse("MAIN");
eval("?".">".$xtpl->text("MAIN"));
?>